package com.example.demoamqp.receiver;

import com.example.demoamqp.conatants.Constants;
import com.example.demoamqp.send.FanoutSender;
import com.example.demoamqp.service.EmailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 发布订阅/fanout模式
 * 消费者
 *
 * @className: MqFanoutReceiver
 * @projectName: demo-one
 * @auth: rosszhang
 * @date: 2023/12/28 15:09
 */
@Slf4j
@Component
public class MqFanoutReceiver {

    private EmailService emailService;
    @Autowired
    public void setEmailService(EmailService emailService) {
        this.emailService = emailService;
    }

    // 指定队列，可以接收缓存到队列里的消息
    @RabbitListener(queues = Constants.MQ_PHONE_QUEUE)
    public void sendPhone(String msg) {
        log.debug("[phone 消费者：]消费{}", msg);
        System.out.println("发送手机验证码：" + msg);
    }

    @RabbitListener(queues = Constants.MQ_MAIL_QUEUE)
    public void sendMail(String message) {
        log.debug("[email 消费者：]消费{}", message);
        emailService.sendSimpleMail("1436561763@qq.com", "登录验证码", message);
    }
}
